package com.dayu.rabbitmq.routing;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

import com.dayu.rabbitmq.util.MQUtil;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

/**
 * @author dayu
 * @date 2019/02/20
 * @Describe 路由模式
 */
public class Send {

    private static String EXCHANGE_NAME = "test_exchange_direct";

    public static void main(String[] args) throws IOException, TimeoutException {
        //获取连接
        Connection connection = MQUtil.getConnection();
        //获取频道
        Channel channel = connection.createChannel();

        channel.exchangeDeclare(EXCHANGE_NAME, "direct");

        String msg = "sdf direct";
        // info,error,..
        String routingKey = "error";
        channel.basicPublish(EXCHANGE_NAME, routingKey, null, msg.getBytes());
        System.out.println(" send " + msg);
        channel.close();
        connection.close();
    }
}
